package app.server.project.main.service.dto.rank;

import app.server.project.main.service.db.entity.user.UserInfoEntity;
import cn.hutool.core.bean.BeanUtil;
import lombok.Data;

@Data
public class RankDto {

    /**
     * 排行榜数值
     */
    private long val;
    /**
     * 排行榜比率
     */
    private String rate;
    /**
     * 用户id
     */
    private long userId;
    /**
     * 昵称
     */
    private String nick;
    /**
     * 头像
     */
    private String headUrl;
    /**
     * 等级
     */
    private int lv;
    /**
     * 名次
     */
    private int pos;

    /**
     * 用户id
     */
    private String userIdStr;

    public static RankDto of(UserInfoEntity userRankEntity, long val, long rate) {
        var ret = new RankDto();
        ret.setVal(val);
        ret.setRate(String.valueOf(rate));
        BeanUtil.copyProperties(userRankEntity, ret, true);
        ret.setUserIdStr(String.valueOf(userRankEntity.getUserId()));
        return ret;
    }

    public static RankDto ofCommon(UserInfoEntity userRankEntity, long val) {
        var ret = new RankDto();
        ret.setVal(val);
        BeanUtil.copyProperties(userRankEntity, ret, true);
        ret.setUserIdStr(String.valueOf(userRankEntity.getUserId()));
        return ret;
    }
}
